#include <iostream>
#include <cstdio>
using namespace std;
int t, a[200005],b[200005];
bool color[200005];//red -> 0, blue -> 1;
int n, sum, cnt;
bool vis[200005];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> t;
    while(t --)
    {
        cin >> n;
        for(int i = 1; i <= n; i ++)
        {
            cin >> a[i];
            b[a[i]] ++;
        }
        for(int i = i; i <= n; i ++)
        {
            if(b[a[i]] > 1)
            {
                sum += a[i];
                if(!vis[a[i]])
                {
                    vis[a[i]] = 1;
                    cnt += a[i];
                }
            }
        }
        cout << sum-cnt << endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
